<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<div class="page_right">
    <div>
        <p class="settings_factoryCode_p1">* 工厂简码一经设置，将不可修改。</p>
        <p class="settings_factoryCode_p2">
            <span>工厂简码：</span>
            <span class="settings_factoryCode_code">${!empty shortCode?shortCode:'未设置'}</span>
            <input class="settings_factoryCode_code" type="text" placeholder="请设置工厂简码（2-6位数字、字母）" value="${shortCode}">
            <input type="button" class="settings_factoryCode_setcode" value="确认" disabled="disabled">
        </p>
    </div>
</div>
<script type="text/javascript">
    var reg_factoryCode=/^[0-9a-zA-Z]{2,6}$/;
    if($("span.settings_factoryCode_code").text()=="未设置"){
        $("span.settings_factoryCode_code").stop().hide();
        $("input.settings_factoryCode_code, .settings_factoryCode_setcode").stop().show();
    }else{
        $("span.settings_factoryCode_code").stop().show();
        $("input.settings_factoryCode_code, .settings_factoryCode_setcode").stop().hide();
    }

    //设置工厂简码  输入框
    $("input.settings_factoryCode_code").on("keyup keydown focus", function(){
        var settings_factoryCode_code=$("input.settings_factoryCode_code").val();
        if(reg_factoryCode.test(settings_factoryCode_code)){
            $(".settings_factoryCode_setcode").removeAttr("disabled", "disabled").addClass("cur");
        }else{
            $(".settings_factoryCode_setcode").attr("disabled", "disabled").removeClass("cur");
        }
    });

    //设置工厂简码  确认
    $(".settings_factoryCode_setcode").on("click", function(){
        var settings_factoryCode_code=$("input.settings_factoryCode_code").val();
        if(reg_factoryCode.test(settings_factoryCode_code)){
            $("span.settings_factoryCode_code").text(settings_factoryCode_code);
            $.ajax({
                url: "${basePath}v2/factory/manage/updateShortCode",
                type: 'POST',
                data: {"shortCode":settings_factoryCode_code},
                error: function (response) {
                    $errorMsg(response);
                },
                success: function (ret) {
                    if(ret.result==true){
                        $("span.settings_factoryCode_code").stop().show();
                        $("input.settings_factoryCode_code, .settings_factoryCode_setcode").stop().hide();
                    }else{
                        alert(ret.info);
                    }
                }
            });
        }
    });

</script>